﻿namespace KeRui.Common.IPQuery
{
    using System;
    using System.Web;
    using System.Windows.Forms;

    public class IPQuery
    {
        public static IPLocation App(string ip)
        {
            IPLocator locator = new IPLocator(Application.StartupPath + "/Bin/KeRui.Ip.dat");
            return locator.Query(ip);
        }

        public static IPLocation Query(string ip)
        {
            string dataPath = "";
            try
            {
                dataPath = HttpContext.Current.Server.MapPath("/Bin/") + "KeRui.Ip.dat";
            }
            catch (Exception)
            {
                dataPath = Application.StartupPath + "/Bin/KeRui.Ip.dat";
            }
            IPLocator locator = new IPLocator(dataPath);
            return locator.Query(ip);
        }

        public static IPLocation Web(string ip)
        {
            IPLocator locator = new IPLocator(HttpContext.Current.Server.MapPath("/Bin/") + "KeRui.Ip.dat");
            return locator.Query(ip);
        }
    }
}

